package com.zyp.composite;

import java.util.ArrayList;
import java.util.List;

/**
 * 
 * 非叶子节点，包含子节点
 * @author Administrator
 *
 */
public class Container extends IComponent{
	
	private List<IComponent> list;

	public Container(String name) {
		super(name);
		list=new ArrayList<IComponent>();
	}

	@Override
	public void add(IComponent component) {
		list.add(component);
	}

	@Override
	public void remove(IComponent component) {
		list.remove(component);
	}

	@Override
	public void display(int depth) {
		StringBuilder sb = new StringBuilder("");  
        for (int i = 0; i < depth; i++) {  
            sb.append("-");   
        }  
        System.out.println(new String(sb) + this.getName());  
        for (IComponent c : list) {  
            c.display(depth + 2);  
        }  
	}

}
